//
//  YYVisitorTableViewController.swift
//  YYWeibo
//
//  Created by strongwallyi on 15/12/28.
//  Copyright © 2015年 strongwallyi. All rights reserved.
//

import UIKit

class YYVisitorTableViewController: UITableViewController {

    //代表当前是否登录
    var userLogin: Bool = YYUserAccountViewModel.sharedViewModel.userLogin
    
    //加载视图,给 view 设置值
    override func loadView() {
//        if userLogin == false{
//            let v = UIView()
//            v.backgroundColor = UIColor.orangeColor()
//            view = v
//        }else{
//            super.loadView()
//        }
        
        //简写
        userLogin == true ? super.loadView():setupUI()
        
    }
    
    //设置一个私有的方法
    private func setupUI(){
        //让当前的 view 等于访客的 view
        view = visitorView
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "registerBtnClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", target:  self, action: "loginBtnClick")
        
        visitorView.loginButton.addTarget(self, action: "loginBtnClick", forControlEvents: .TouchUpInside)
        visitorView.registerButton.addTarget(self, action: "registerBtnClick", forControlEvents: .TouchUpInside)
        
    }
    
    func loginBtnClick(){
        print("登陆")
        let vc = YYNavigationController(rootViewController: YYOauthViewController())
        presentViewController(vc, animated: true, completion: nil)
    }
    
    func registerBtnClick(){
        print("注册")
        let vc = YYNavigationController(rootViewController: YYOauthViewController())
        
        presentViewController(vc, animated: true, completion: nil)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    //懒加载 view 控件
    lazy var visitorView: YYVisitorView = YYVisitorView()
    
}
